//
//  JokeTextTableViewCell.m
//  zby
//
//  Created by lanou on 15/12/16.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "JokeTextTableViewCell.h"
#import "JokeText.h"

@implementation JokeTextTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 30)];
        [self.contentView addSubview:_label1];
        self.label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, kWidth-20, 100)];
        _label2.font =[UIFont systemFontOfSize:18];
        _label2.numberOfLines = 0;
        [self.contentView addSubview:_label2];
        
        UIButton *button = [UIButton buttonWithType:(UIButtonTypeSystem)];
        button.frame = CGRectMake(kWidth-20-50, 50+_label2.frame.size.height+10, 50, 30);
        
        [button setImage:[UIImage imageNamed:@""] forState:(UIControlStateNormal)];

        [self.contentView addSubview:button];
    }
    
    return self;
    
    
}

-(void)setJoke:(JokeText *)joke{
    
    if (_joke != joke) {
        _joke = joke;
        
        _label1.text = joke.category_name;
        _label2.text = joke.text;
        
        CGRect rec = _label2.frame;
        rec = CGRectMake(rec.origin.x, rec.origin.y, rec.size.width, [JokeTextTableViewCell heightForString:joke.text]);
        _label2.frame = rec;
        
    }

}

+(CGFloat)heightForString:(NSString *)string{
    
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:18] forKey:NSFontAttributeName];
    
    CGRect bound = [string boundingRectWithSize:CGSizeMake(kWidth-20, 1000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
    
    return bound.size.height;
    
    
}

+(CGFloat)cellHeightForJoke:(JokeText *)joke{
    
    CGFloat height = 100+[JokeTextTableViewCell heightForString:joke.text];
    return height>100?height:100;

}









- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
